#!/bin/bash
#
# Module for ensuring that the Pulley UUID is set.
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 19 November 2013
#
#   Copyright 2012-2013 Coastal Carolina University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#


## p_uuid_update
##
## Sets a Pulley installation UUID for the current system, if one is not
## already set. This UUID allows individual virtual or other machines
## running Pulley to be targeted for management and reporting purposes.
## Returns 0 on success, non-zero on failure.
##
function p_uuid_update() {
	local status=0
	local my_uuid=$(get_context pulley/uuid)
	
	if [[ -z "${my_uuid}" ]]; then
		my_uuid=$(uuidgen)
		status=$?
		
		if ((status == 0)); then
			set_context pulley/uuid "${my_uuid}"
			status=$?
		fi
	fi
	return ${status}
}
